package com.example.service.impl;


import com.example.service.FileService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Service
//@Primary
public class FileServiceImpl implements FileService {


    @Override
    public String saveFile(MultipartFile file) throws IOException {

        String originalFilename = file.getOriginalFilename();

        String[] arr = originalFilename.split("\\.");
        String ext = arr[arr.length - 1];
        String newname = UUID.randomUUID().toString() + "." + ext;
        File file1 = new File("D://a//" + newname);

        file.transferTo(file1);

        return file1.getAbsolutePath();
    }
}
